package com.xiguaji.tiktok.v1.tiktok.help.repository;

import com.xiguaji.tiktok.v1.tiktok.help.dto.HelpCenterArticleSummaryDto;
import com.xiguaji.tiktok.v1.tiktok.help.model.HelpArticle;
import com.xiguaji.tiktok.v1.tiktok.help.model.HelpMenuArtcleStatic;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface HelpArticleRepository  extends CrudRepository<HelpArticle,Long>,HelpArticleExtRepository {

    //获取菜单下需展示的所有文章列表
    @Query("SELECT id,title, url_suffix url,menu_id ,update_time ,create_time ,create_by ,update_by  FROM help_article " +
            " WHERE menu_id = :menuId  AND display = 1 " +
            " ORDER BY update_time DESC " )
    List<HelpCenterArticleSummaryDto> findAllArticlesSummary(Long menuId);
     int countAllByMenuId(Long menuId);
//    Page<HelpArticle> findAllByMenuId(Long menuId, Pageable pageable);
    List<HelpArticle> findAllByMenuId(Long menuId, Pageable pageable);
    //统计菜单下的文章数量
    @Query("SELECT menu_id ,max(id) id,max(url_suffix) url,count(1) AS articles FROM help_article " +
            " WHERE display = 1 " +
            " GROUP BY menu_id  " )
    List<HelpMenuArtcleStatic> findHelpArticlesStatic();


}
